package com.example.web_back.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.web_back.entity.*;
import com.example.web_back.mapper.HotelMapper;
import com.example.web_back.mapper.HotelOrderMapper;
import com.example.web_back.mapper.RoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@CrossOrigin
@RestController
@RequestMapping("/hotel")
public class HotelController {

    @Autowired
    private HotelMapper hotelMapper;

    @Autowired
    private HotelOrderMapper hotelOrderMapper;

    @Autowired
    private RoomMapper roomMapper;

    @PostMapping("/getHotelInfo")
    public List<Hotel> getHotelInfo(){
        List<Hotel> hotelList = hotelMapper.selectList(null);
        return hotelList;
    }

    @PostMapping("/getRoomInfo")
    public List<HotelRoom> getHotelRoomInfo(@RequestBody int id){
        List<HotelRoom> hotelRoomList = roomMapper.selectList(Wrappers.<HotelRoom>lambdaQuery().eq(HotelRoom::getHotelid,id));
        System.out.println(hotelRoomList);
        return hotelRoomList;
    }

    @PostMapping("/submitorder")
    public Result submitOrder(@RequestBody HotelOrder hotelOrder){
        hotelOrderMapper.insert(hotelOrder);
        return Result.success();
    }

}
